include<ub.scad>; //⇒ v.gd/ubaer or https://github.com/UBaer21/UB.scad
/*[Hidden]*/
designVersion="1.0";
designer="Ulrich Bär";
license="CC0";
useVersion=24.055;//(sites.google.com/site/ulrichbaer)
assert(Version>=useVersion,str("lib version ",Version," detected, include ",useVersion," ub.scad library‼ ⇒http://v.gd/ubaer"));
/*[Basics]*/
nozzle=.2;
bed=false;
pPos=[0,0];
info=false;
name=undef;
hires=true;
vp=false;

/*[Power Bank]*/


lid=[20,13];
cut=5;


T(printPos)Cut()PrevPos(z=cut +0.1,rot=0)PB();

//cap
T(printPos)Cut()PrevPos(rot=0,tP=[0,25])PB(part=1);

if($preview)T(y=-2.3,z=1.5)R(90,0,180)AZ_PCB();

module AZ_PCB(){
Rod(size=[10,68,6]);
color("teal")T(y=10)cube([18.2,20,1],true);
color(alpha=.4)T(y=.15/2-1.8,z=6.9/2+.5+.75) cube([14.5,.15,6.9],true);// type A
T(y=15.3/2-1.8,z=6.9/2+.5+.75) cube([13.1,15.3,5.6],true);// type A
T(y=5.6/2-1.8,z=-2.8/2-.5)cube([7.4,5.6,2.8],true);//micro B

color("red") T(18.2/2 -1.5,3,z=-.9-.5)cube([.9,2,.9]);
color("lime")T(18.2/2 -2.5,3,z=-.9-.5)cube([.9,2,.9]);
T(0,20+25,2)color("blue",.25)cube([20,50,11],true);

}



module PB(h=75,dicke=.8,n=3,lid=lid,part=0){
//r=[11.5,9,h/2];
cutH=cut;
cutBot=3.5;
r=[11.5,9,h/2+cutBot/2];
lidR=3.75;
pcbPos=[0,-2.3];

  if(part==0)Halb(size=h+10)difference(){
    Tz(r.z-cutH -cutBot)Superellipse(n=n,n3=6,r=r);
    difference(){
      Halb(0,t=[0,0,1.5],size=h+10)Tz(r.z-cutH -cutBot)Superellipse(n=n,n3=6,r=vAdd(r,-dicke) );
      Tz(-.1)LinEx(5)offset(spiel +2)Quad(lid,rad=lidR);//wall around lid
    }
    
    Tz(+3)Rundrum(vAdd(lid,spiel*2),r=lidR+spiel)Vollwelle(.25,extrude=0,x0=-.1,xCenter=-1);
    Tz(-.1)Roof(8,[.5,0],deg=-45)offset(spiel)Quad(lid,rad=lidR,fs=.5);
  }

  if(part==1){
  
 // pcb guide
  T(pcbPos+[-lid.x/2,0.65]) cube([1.5,1,3]);
  T(pcbPos+[lid.x/2-1.5,.65]) cube([1.5,1,3]);
 
   difference(){
      union(){
        Tz(cutH-.1)LinEx(5)Quad(lid,rad=lidR);
        Tz(-cutBot)Halb(1,size=100,t=[0,0,cutH+cutBot])Tz(r.z)Superellipse(n=n,n3=6,r=r);
        Tz(3+cutH+.1)Rundrum(lid,r=lidR)Vollwelle(.15,.35,extrude=0,x0=-.1,xCenter=-1);
        Tz(cutH)Rundrum(lid,r=lidR)Kehle(rad=.6,fn=1);
      }
      Tz(.75)LinEx(20)offset(-.5)Quad(lid,rad=lidR);
      scale([1,1,-1])cylinder(d=100,h=100,$fn=12);
      
  //usb
      T(pcbPos+[0,1.7],z=-.5)LinEx(25){
        T(y=3.0){// type A
            offset(1)square([12,4.5],true); // type A core
            offset(.1){
              square([12,7],true); // type A rim
              square([14.5,4],true); // type A rim
            }
        }
        T(y=-.5-3.0)Quad([8,3],rad=.75);//micro B
        T(-7.5,-.5-3)circle(d=2);//led
      }
    }
  }

}



// version Info
if(string2num(designVersion[2])>0)T(1,-1)color("navy")linear_extrude(.1)Seg7(str(designVersion),h=1,spiel=0.01,b=.05,ratio=0.5,center=true,name=0);